import java.util.StringTokenizer;

class P278 {

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		for (int k = 0; k < cases; k++) {
			StringTokenizer st = new StringTokenizer(readLn());
			char p = st.nextToken().charAt(0);
			int r = Integer.parseInt(st.nextToken());
			int c = Integer.parseInt(st.nextToken());
			switch (p) {
			case 'r':
				System.out.println(Math.min(r, c));
				break;
			case 'k':
				System.out.println(((r * c) + 1)/ 2 );
				break;
			case 'Q':
				System.out.println(Math.min(r, c));
				break;
			case 'K':
				System.out.println(((r + 1)/2)*((c + 1)/2));
				break;
			}
		}
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

}
